### Alizade, Dancygier, Ditlmann
### "National Penalties Reversed"
### Replication Code 
### Table A3
### For questions, contact jalizade@princeton.edu

# setup
rm(list = ls())
setwd("C:/Users/Jey/Dropbox/WZB/NaturalizationExperiment/Submission/JOP/replication_JOP/data")
library(foreign)
dat <- read.dta("data_experimental.dta")
datmun <- read.dta("data_covars_mun.dta")

# filter first experiment
dat <- dat[dat$e1_treated==1,]
datmun <- datmun[datmun$e1_treated==1,]

# code FDP as not center-left for the purposes of this table
dat$e1_leftpol[dat$e1_treated==1 & is.na(dat$e1_leftpol)] <- 0

# function to get summary statistics for both the experimental and the baseline sample
statscomp <- function(df, var) {
  data.frame(exp_mean = mean(df[,var], na.rm=T), exp_sd = sd(df[,var], na.rm=T),
             base_mean = mean(df[df$e1_base_treated==1,var], na.rm=T), base_sd = sd(df[df$e1_base_treated==1,var], na.rm=T))
}

# sample size
c(sum(dat$e1_treated==1), sum(dat$e1_base_treated==1))

# get summary statistics for aggregate-level variables
t(sapply(c("pop", "pop_density", "pct_forcit_pop", "pct_welfare", "pct_coll_qual", "east", "e1_n_council", "e1_pct_left", "e1_pct_bigpart"), 
         function(x) statscomp(datmun, x)))

# get summary statistics for individual-level variables
t(sapply(c("e1_fempol", "e1_agepol", "e1_leftpol"), function(x) statscomp(dat, x)))

